home *** CD-ROM | disk | FTP | other *** search
- Path: newsie.dmc.com!usenet
- From: prozac@cape.com
- Newsgroups: comp.lang.c
- Subject: Re: File problem with Watcom C/C++ 10.5
- Date: 9 Apr 1996 20:30:01 GMT
- Organization: Just Some Guy
- Distribution: world
- Message-ID: <4kehca$iar@newsie.dmc.com>
- References: <4k9fds$4fs@sparcserver.lrz-muenchen.de>
- NNTP-Posting-Host: tsa_65.cape.com
- Mime-Version: 1.0
- Content-Type: Text/Plain; charset=US-ASCII
- X-Newsreader: WinVN 0.99.6
-
- >From: Ralph Reichart <reichart@informatik.tu-muenchen.de>
- >Newsgroups: comp.lang.c
- >Subject: File problem with Watcom C/C++ 10.5
- >
- >#include <stdlib.h>
- >#include <stdio.h>
- >
- >main()
- >{
- > FILE *Datei;
- >
- > Datei = fopen("\autoexec.bat", "r");
- > if (Datei == NULL)
- > {
- > printf("\nSHIT!!");
- > exit(1);
- > };
- > fclose(Datei);
- >}
- >
- >i'm sorry, but i can't open it. i always have the value -1 or 1 in errno.
- >yes, the file exists, but it doesn't matter. it never works.
- >can somebody please help me??
-
- There is a more or less obvious error in the string literal
- that makes up the file name (look hard, you'll find it ;-).
-
- Here's two good tips for getting your code to help you
- find out out why library functions (many of them anyway):
-
- Use the error reporting library functions.
-
- Use string pointers instead of literals for your
- diagnostic messages.
-
- Try this and IT WILL TELL YOU WHAT THE ERROR IS:
-
- #include <stdlib.h>
- #include <stdio.h>
- #include <errno.h>
-
- main()
- {
- FILE *Datei;
- char *File = "\autoexec.bat";
-
- errno = 0;
- Datei = fopen(File, "r");
- if (Datei == NULL)
- {
- printf("\nSHIT!!");
- perror(File);
- exit(1);
- };
- fclose(Datei);
- }
-
- See what the error is now?
-
- The standard library is YOUR FRIEND!
-
-
-